package ccapp;

import java.util.Calendar;
import java.util.List;

import ccapp.util.CreditCardSystemConstants;
import frmsystem.Account;
import frmsystem.IEntry;

public class CreditCard extends Account{

	public double getMinPayment() {
		return 0;
	}

	public String getName()
	{
		return "CREDIT CARD TYPE";
	}
	
	@Override
	public String getReportAll() {
		String report = "CC Type = "+getName()+" \n" ;
	
		Calendar calendarLast = Calendar.getInstance(); 
		calendarLast.set(Calendar.DATE, calendarLast.getActualMaximum(Calendar.DATE)); 
		
		Calendar calendarFirst = Calendar.getInstance(); 
		calendarFirst.set(Calendar.DATE, calendarFirst.getActualMinimum(Calendar.DATE)); 
		
		double previousBalance=0, totalCharges=0, totalCredits=0, newBalance=0, 
		totalDue = 0;
		
		for(IEntry entry : entries){
			//if(calendarFirst.after(entry.getDate()) && calendarLast.before(entry.getDate())){
				if(entry.getType() == CreditCardSystemConstants.TRANSACTION_CHARGE){
					totalCharges += entry.getAmount();
				}
				else if (entry.getType() == CreditCardSystemConstants.TRANSACTION_DIPOSIT){
					totalCredits += entry.getAmount();
				}    			
			//}
	    }
		
		/*Charge charge = new Charge(this);
		totalCharges = charge.getTotal(entries, calendarFirst, calendarLast);
		
		Deposit deposite = new Deposit(this);
		totalCredits = deposite.getTotal(entries, calendarFirst, calendarLast);*/
		 
		
		previousBalance = currentAmmount + totalCredits - totalCharges;
		
		newBalance = previousBalance - totalCredits + totalCharges * getInterestRate() * (previousBalance - totalCredits);
		totalDue = getMinPayment() * newBalance;
		
		report += "Previous balance = $" + previousBalance + "\n";
		report += "Total Credits = $" + totalCredits + "\n";
		report += "Total Charges = $" + totalCharges + "\n";    	
		report += "New balance = $" + newBalance + "\n";
		report += "Total Amount Due = $" + totalDue + "\n";
		
		return report;
	}
	

}
